using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX.DirectDraw;

namespace Zsa.Emulation.Render.Video.Gdi
{
    /// <summary>
    /// Settings used to create a direct 3d device
    /// </summary>
    public class GdiRenderSettings : GraphicRenderSettings
    {

        #region Fields

        private CreateFlags _CreateFlags;

        private CooperativeLevelFlags _CooperativeFlags;

       
        #endregion Fields

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="T:D3dRenderSettings"/> class.
        /// </summary>
        /// <param name="item">The item.</param>
        public GdiRenderSettings(RenderDeviceItem item)
            : base ( item )
        {
        }
        #endregion Constructor

        #region Properties
        /// <summary>
        /// Gets a value indicating whether this instance is device specific.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is device specific; otherwise, <c>false</c>.
        /// </value>
        public bool IsDeviceSpecific
        {
            get
            {

                return DeviceGuid != Guid.Empty;
                
            }
        }

        /// <summary>
        /// Gets the device GUID.
        /// </summary>
        /// <value>The device GUID.</value>
        public Guid DeviceGuid
        {
            get
            {    
                if ((base.DeviceItem.Id is Guid))
                {
                    Guid _Guid = (Guid)base.DeviceItem.Id;    
                    return _Guid;
                }
                return Guid.Empty;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [use emulation].
        /// </summary>
        /// <value><c>true</c> if [use emulation]; otherwise, <c>false</c>.</value>
        public bool UseEmulation
        {
            get
            {
                return (_CreateFlags & CreateFlags.EmulationOnly) == CreateFlags.EmulationOnly;
            }
            set
            {
                if (value)
                {
                    _CreateFlags = CreateFlags.EmulationOnly;
                }
                else
                {
                    _CreateFlags = CreateFlags.Default;
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [use hardware].
        /// </summary>
        /// <value><c>true</c> if [use hardware]; otherwise, <c>false</c>.</value>
        public bool UseHardware
        {
            get
            {
                return (_CreateFlags & CreateFlags.HardwareOnly) == CreateFlags.HardwareOnly;
            }
            set
            {
                if (value)
                {
                    _CreateFlags = CreateFlags.HardwareOnly;
                }
                else
                {
                    _CreateFlags = CreateFlags.Default;
                }
            }
        }

        /// <summary>
        /// Gets the create flags.
        /// </summary>
        /// <value>The create flags.</value>
        public CreateFlags CreateFlags
        {
            get
            {
                return _CreateFlags;
            }
        }

        /// <summary>
        /// Gets the cooperative level flags.
        /// </summary>
        /// <value>The cooperative level flags.</value>
        public CooperativeLevelFlags CooperativeLevelFlags
        {
            get
            {
                return _CooperativeFlags;
            }
        }

        /// <summary>
        /// The capabilties of the renderer
        /// </summary>
        /// <value></value>
        public override GraphicRenderCapabilities Capabilities
        {
            get
            {
                return new GdiRenderCapabilities();
            }
        }

        #endregion Properties

        #region Methods
        /// <summary>
        /// Creates the device.
        /// </summary>
        /// <returns></returns>
        public override GraphicRender CreateDevice()
        {
            return new GdiGraphicRender(this);
        }


        /// <summary>
        /// Checks to see if the settings are valid.
        /// </summary>
        /// <returns></returns>
        public override bool IsValid()
        {
            return true;
        }

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the other parameter; otherwise, false.
        /// </returns>
        public override bool Equals(GraphicRenderSettings other)
        {
            // Try to cast to type.
            GdiRenderSettings _OtherSettings = other as GdiRenderSettings;
            // If type not valid or param was null then return false
            if (_OtherSettings == null)
            {
                return false;
            }
            return true;
        }

        #endregion Methods
    }
}
